package cn.tedu.boot11.controller;

import cn.tedu.boot11.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
public class HelloController {

/*    @RequestMapping("/hello")
    public void hello(HttpServletResponse response) throws IOException {
        System.out.println("服务器接收到了请求!");
        //设置响应类型 以及字符集
        response.setContentType("text/html;charset=utf-8");
        //得到输出对象 异常抛出
        PrintWriter pw = response.getWriter();
        //输出数据
        pw.print("你好 我是服务器!<b>我是标签</b>");
        //关闭资源
        pw.close();
    }*/

    @RequestMapping("/hello")
    @ResponseBody //此注解通过返回值给客户端发送页面
    public String hello(HttpServletRequest request){
        String info = request.getParameter("info");
        return "你好 我是服务器<b>我是标签</b> 我是参数:"+info;
    }

   /* @RequestMapping("/reg")
    @ResponseBody()
    public String reg(String username,String password,String nick,int age){
        System.out.println("username = " + username + ", password = " + password + ", nick = " + nick + ", age = " + age);
        return "成功!";
    }*/

    @RequestMapping("/reg")
    @ResponseBody
    public String reg(User user){
        System.out.println("user = " + user);
        return "成功";
    }
}
